#include "Matrice.h"


Matrice::Matrice() {}

Matrice::Matrice(const Point &origine, const Point &destination) {
	Vecteur v(origine,destination);
	v.normaliser();
	
	Vecteur w(0.000000001f,1,0);
	w.normaliser();
	Vecteur u = v.prodVect(w);
	u.normaliser();

	w = v.prodVect(u);
	w.normaliser();

	elems[0][0] = u.getX();
	elems[0][1] = w.getX();
	elems[0][2] = v.getX();
	elems[0][3] = origine.getX();
	elems[1][0] = u.getY();
	elems[1][1] = w.getY();
	elems[1][2] = v.getY();
	elems[1][3] = origine.getY();
	elems[2][0] = u.getZ();
	elems[2][1] = w.getZ();
	elems[2][2] = v.getZ();
	elems[2][3] = origine.getZ();
	elems[3][0] = 0;
	elems[3][1] = 0;
	elems[3][2] = 0;
	elems[3][3] = 1;
}


Matrice::~Matrice() {}


Matrice Matrice::operator *(const Matrice &m) {
	Matrice r;
	
	for (int i=0; i < 4; i++) {
		for (int j=0; j < 4; j++) {
			r.elems[i][j] = 0.0;
			for (int k=0; k < 4; k++) {
				r.elems[i][j] += elems[i][k]*m.elems[k][j];
			}
		}
	}

	return r;
}
Vecteur Matrice::operator *(const Point &p) {
	Vecteur v;
	v.setX(elems[0][0]*p.getX()+elems[0][1]*p.getY()+elems[0][2]*p.getZ()+elems[0][3]*p.getT());
	v.setY(elems[1][0]*p.getX()+elems[1][1]*p.getY()+elems[1][2]*p.getZ()+elems[1][3]*p.getT());
	v.setZ(elems[2][0]*p.getX()+elems[2][1]*p.getY()+elems[2][2]*p.getZ()+elems[2][3]*p.getT());
	v.setT(0);

	return v;
}

Matrice Matrice::getTransposee() const {
	Matrice r;
	
	for (int i=0; i < 4; i++) {
		for (int j=0; j < 4; j++) {
			r.elems[i][j] = elems[j][i];
		}
	}

	return r;
}